package com.a3dweijing.wetouch2.adapter;

import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.Util.ImageLoaderUtil;
import com.a3dweijing.wetouch2.bean.DiscussMsg;
import com.a3dweijing.wetouch2.divView.CircleImageView;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by yxd on 2017/11/3.
 */

public class VideoDiscissRecAdapter extends RecyclerView.Adapter<VideoDiscissRecAdapter.MyViewHolder> {
    private List<DiscussMsg.DiscussVideoListBean> discussVideoListBeen;
    private SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

    public VideoDiscissRecAdapter(List<DiscussMsg.DiscussVideoListBean> discussVideoListBeen) {
        this.discussVideoListBeen = discussVideoListBeen;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_video_discuss,parent,false));
    }

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.name.setText(discussVideoListBeen.get(position).getUser_name());
        holder.content.setText(discussVideoListBeen.get(position).getDiscuss_content());
        ImageLoaderUtil.getLoader().loadImg4(discussVideoListBeen.get(position).getUser_head(),holder.head);
        holder.time.setText(simpleDateFormat.format(new Date(discussVideoListBeen.get(position).getDiscuss_date())));
    }

    @Override
    public int getItemCount() {
        return discussVideoListBeen.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        CircleImageView head;
        TextView name;
        TextView time;
        TextView content;

        public MyViewHolder(View itemView) {
            super(itemView);
            head= (CircleImageView) itemView.findViewById(R.id.user_head);
            name= (TextView) itemView.findViewById(R.id.user_name);
            time= (TextView) itemView.findViewById(R.id.discuss_time);
            content= (TextView) itemView.findViewById(R.id.discuss_content);
        }
    }
}
